Skip to content

otelconf: register Prometheus reader with a MeterProvider in tests - #9475

Open
pujitha24 wants to merge 4 commits into
open-telemetry:mainfrom
pujitha24:auto/issue-7641
Open

otelconf: register Prometheus reader with a MeterProvider in tests#9475
pujitha24 wants to merge 4 commits into
open-telemetry:mainfrom
pujitha24:auto/issue-7641

Conversation

@pujitha24

Copy link
Copy Markdown
Contributor

Motivation:
TestPrometheusIPv6 and TestPrometheusReaderConfigurationOptions in
otelconf/v0.2.0 and otelconf/v0.3.0 call prometheusReader() directly
to build a Prometheus-backed sdkmetric.Reader and then scrape its
/metrics endpoint over HTTP, without ever registering the reader with
an sdkmetric.MeterProvider. Because the reader is never registered,
scraping triggers a "reader is not registered" error from the SDK,
which the default global error handler logs to stderr. The tests still
pass, but they print noisy, misleading error output on every run.

Approach:
Wrap the reader in sdkmetric.NewMeterProvider(sdkmetric.WithReader(reader))
before scraping /metrics, and shut the MeterProvider down (which
transitively shuts down the registered reader) instead of calling
reader.Shutdown directly. This mirrors the existing pattern already
used by TestPrometheusReaderDotStyleLabels in the same files.
TestPrometheusReaderHostParsing was left untouched since it never
scrapes /metrics and never triggered the warning.

This is a test-only change; no production code or behavior is
affected.

Validation:
Ran go build ./..., go vet ./..., and go test ./... -race in both
otelconf/v0.2.0 and otelconf/v0.3.0 (all pass), and
golangci-lint run ./... in both directories (0 issues). Confirmed via
go test ./... -v 2>&1 | grep -i "reader is not registered" that the
warning no longer appears in either module's test output, whereas it
was present before this change.

Report: #7641
Signed-off-by: Pujitha Paladugu 10557236+pujitha24@users.noreply.github.com

Fixes #7641

Motivation:
TestPrometheusIPv6 and TestPrometheusReaderConfigurationOptions in
otelconf/v0.2.0 and otelconf/v0.3.0 call prometheusReader() directly
to build a Prometheus-backed sdkmetric.Reader and then scrape its
/metrics endpoint over HTTP, without ever registering the reader with
an sdkmetric.MeterProvider. Because the reader is never registered,
scraping triggers a "reader is not registered" error from the SDK,
which the default global error handler logs to stderr. The tests still
pass, but they print noisy, misleading error output on every run.

Approach:
Wrap the reader in sdkmetric.NewMeterProvider(sdkmetric.WithReader(reader))
before scraping /metrics, and shut the MeterProvider down (which
transitively shuts down the registered reader) instead of calling
reader.Shutdown directly. This mirrors the existing pattern already
used by TestPrometheusReaderDotStyleLabels in the same files.
TestPrometheusReaderHostParsing was left untouched since it never
scrapes /metrics and never triggered the warning.

This is a test-only change; no production code or behavior is
affected.

Validation:
Ran `go build ./...`, `go vet ./...`, and `go test ./... -race` in both
otelconf/v0.2.0 and otelconf/v0.3.0 (all pass), and
`golangci-lint run ./...` in both directories (0 issues). Confirmed via
`go test ./... -v 2>&1 | grep -i "reader is not registered"` that the
warning no longer appears in either module's test output, whereas it
was present before this change.

Report: open-telemetry#7641
Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
@pujitha24
pujitha24 requested review from a team and pellared as code owners August 14, 2026 06:46
@github-actions
github-actions Bot requested a review from codeboten August 14, 2026 06:46
The changelog CI check requires every PR touch CHANGELOG.md unless it
carries a "[chore]" title prefix or the "Skip Changelog" label. Add a
Fixed entry for the otelconf Prometheus reader test fix to satisfy the
check.

Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.5%. Comparing base (b876894) to head (f167911).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #9475   +/-   ##
=====================================
  Coverage   84.5%   84.5%           
=====================================
  Files        203     203           
  Lines      16805   16805           
=====================================
+ Hits       14204   14215   +11     
+ Misses      2121    2110   -11     
  Partials     480     480           

see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.


// Register the reader with a MeterProvider so that scraping
// /metrics below does not log a "reader is not registered" error.
mp := sdkmetric.NewMeterProvider(sdkmetric.WithReader(rs))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like TestPrometheusIPv6 in otelconf/x/metric_test.go has the same pattern and still logs this warning. Should we update that test as well?

Comment thread CHANGELOG.md Outdated
- Report `ot-baggage-*` extraction errors from `go.opentelemetry.io/contrib/propagators/ot` to `otel.Handle` instead of silently discarding them, while still attaching the successfully parsed baggage members to the context. (#9395)
- Set `error.type` on the `rpc.client.call.duration` and `rpc.server.call.duration` metrics in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc` when the RPC fails with a non-OK status, per the RPC semantic conventions. (#9429)
- Reject OTLP exporter headers with an empty `name` in `go.opentelemetry.io/contrib/otelconf`, `go.opentelemetry.io/contrib/otelconf/x`, and `go.opentelemetry.io/contrib/otelconf/v0.3.0`, instead of forwarding invalid header names to OTLP exporters. (#9102)
- Register the Prometheus reader with a `sdkmetric.MeterProvider` in the `go.opentelemetry.io/contrib/otelconf` and `go.opentelemetry.io/contrib/otelconf/v0.3.0` test suites, removing a noisy "reader is not registered" error logged to stderr during test runs. (#9475)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A changelog is not needed for this

@dashpole dashpole added the Skip Changelog Allow PR to succeed without requiring an addition to the CHANGELOG label Aug 14, 2026
…usIPv6

Also drop the changelog entry per review feedback (not needed for a
test-only change).

Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
Comment thread otelconf/x/metric_test.go Outdated
Comment on lines +1620 to +1621
// Register the reader with a MeterProvider so that scraping
// /metrics below does not log a "reader is not registered" error.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these comments are needed

Per review feedback, remove the explanatory comment restating that
registering the reader with a MeterProvider avoids a "reader is not
registered" log during scraping. Applied to all three instances added
by this PR, not just the one flagged inline.

Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Skip Changelog Allow PR to succeed without requiring an addition to the CHANGELOG

Projects

None yet

Development

Successfully merging this pull request may close these issues.

otelconf : Prometheus Reader fails with "reader is not registered" warnings

3 participants